<?php
$category  = gpc_getIntGet('cat');

if($actPost=='save')
{
    $type       = gpc_getIntPost('Category');
    $listorder	= gpc_getStringArray("listorder");
    $listid		= gpc_getStringArray("listid");
    $listvalue1	= gpc_getStringArray("listvalue1");

    for($i=0;$i<count($listvalue1);$i++)
    {
    	$idc   = intval($listid[$i]);
    	$order = intval($listorder[$i]);
    	$vl1   = trim($listvalue1[$i]);  
        
        
    	if(empty($vl1) && $vl1!=-1)continue;
    	
    	if($vl1==-1 && $idc>0)
        {
            $sql_delete="delete from tblcustomfield where iId=$idc";
            $dbsql->query($sql_delete);
        }else if($idc==0)
    	{
    		$sql_insert="insert into tblcustomfield 
    				(iType,cName,iOrder) 
    		values($type,'$vl1',$order)";
    		
    		$dbsql->query($sql_insert);
    	}else
    	{
    		$sql_update="update tblcustomfield set
    					cName='$vl1',
    					iOrder='$order'
    					where iId=$idc";
    					
    		$dbsql->query($sql_update);
    	}
    }
    $msg = "Save Custom field Success !";
    $page = "?module=$module&opt=customfield&cat=$category";
    page_transfer($msg,$page);
}
$listfields = listCustomField($category);
